import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			this.getList(this);
		},
		//获取列表
		getList(that,params,pageIndex = 1,pageSize = 10) {
			params = params || {businessType:131};
			var apiTest = this.apiTest;
			this.$ajax({
					method: 'post',
					url:apiTest+'/supplier/whWarehouse/list',
					data:{
						condition:params,
						pageIndex: pageIndex,
						pageSize: pageSize,
					}
			    }).then((res)=>{
					that.Model.tableData = [];
					var data = res.data;
					if(data.status == 200){
						var obj = {};
						var pagination = commonObject.paginationFunction(data.result);
						that.Model.paginationObject = objDeepCopy(pagination);
						var result = data.result.result;
						if(result){
							for (var i = 0; i < result.length; i++) {
								obj = objDeepCopy(result[i]);
								if(result[i].typeDict){
									obj.remarkType = result[i].typeDict.value;
								}
								if(result[i].statusDict){
									obj.showStatus = result[i].statusDict.value;
								}
								that.Model.tableData.push(obj)
							}
						}
					}else{
			
					}
				});
		},
		
		//新建调拨单
		newPage(){
			this.$router.push({
				path:'certificationStorageListNew',
				query:{
					
				}
			});
		},
		//详情
		toDetial(row) {
			this.$router.push({
				path:'certificationStorageListDetail',
				query:{
					number:row.number
				}
			});
		},
		//
		orderEdit(row){
			this.$router.push({
				path:'certificationStorageListEdit',
				query:{
					number:row.number
				}
			});
		},
		//作废 或者 入库
		orderObsolete(row,type) {
			if(type == 'obsolete'){
				this.$confirm('作废该入库单后，则无法再对该单进行操作，是否确定作废?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(() => {
					this.obsoleteAjax(this,131,row.id)
				}).catch(() => {
				    
				});
			}else if(type == 'in'){
				this.$confirm('入库后，则无法再对该单进行操作，是否确定入库?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(() => {
					this.inAjax(this,row.id)
				}).catch(() => {
				    
				});
			}
		},
		//作废 ajax
		obsoleteAjax(that,businessType,id){
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'get',
				url:apiTest+'/supplier/whWarehouse/cancel/'+businessType+'/'+id,
			}).then((res)=>{
				console.log(res);
				if(res.data.status == 200){
					var result = res.data.result;
					that.tips(that,'success','操作成功')
					that.getList(that);
				}else{
					that.tips(that,'warning',data.msg)
				}
			});
		},
		//入库 ajax
		inAjax(that,id){
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'get',
				url:apiTest+'/supplier/whWarehouse/updateAuthIn/'+id,
			}).then((res)=>{
				console.log(res);
				if(res.data.status == 200){
					var result = res.data.result;
					that.tips(that,'success','操作成功')
					that.getList(that);
				}else{
					that.tips(that,'warning',data.msg)
				}
			});
		},
		//
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			
		},
		handleCurrentChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,val);
		},
		handleSizeChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params);
		},
		toClear(val) {
			this.Model.searchFromData = {};
		},
		toExport(val) {
		  console.log(val);
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	},
	watch:{
		$route:{
		　　　handler(newValue, oldValue) {
				
		　　　},
		　　　deep: true
		},
  	
	},
	filters:{
		objFilters:function(value){
			
		}
	}
}
export default Controller;
